import { getToken } from '@/utils/storage'
import { Message } from 'element-ui'
// import { from } from 'core-js/core/array'
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/dashboard',
      component: () => import('@/views/layout'),
      children: [
        { path: '/dashboard', component: () => import('@/views/dashboard') },
        { path: '/article', component: () => import('@/views/article') }

      ]
    },
    { path: '/login', component: () => import('@/views/login') }
  ]
})

const whiteList = ['/login']
router.beforeEach((to, from, next) => {
  if (getToken() || whiteList.includes(to.path)) return next()
  next('/login')
  Message.error('请您先登录哦')
})

export default router
